package com.hiwan.system.common.web.servlets;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hiwan.platform.util.BeanUtils;
import com.hiwan.platform.util.StackTraceUtil;
import com.hiwan.system.common.web.HiwanFrameworkSysManager;

/**
 * 系统初始化Servlets进行相关数据的处理和系统初始化
 * 
 * @author WQ
 * 
 */
public class HiwanSysInitInfoServlet extends HttpServlet {
	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// super.doGet(req, resp);
		// 可以直接通过get方式进行该servlet的初始化,进行系统缓存等数据的刷新
		init(this.getServletConfig());
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

	/**
	 * 系统初始化
	 */
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);

		try {
			logger.info("begin to init HiwanSysInitInfoServlet....");
			HiwanFrameworkSysManager hiwanFrameworkSysManager = BeanUtils
					.getBean("hiwanFrameworkSysManager",
							HiwanFrameworkSysManager.class);
			logger.info("hiwanFrameworkSysManager : {}",
					hiwanFrameworkSysManager);
			hiwanFrameworkSysManager.hiwanFrameworkSysInit(config);
			logger.info("end to init HiwanSysInitInfoServlet....");
		} catch (Exception ex) {
			logger.error(StackTraceUtil.getStackTrace(ex));

		}

	}

	private static final long serialVersionUID = 7375067440896334363L;

}
